

<template>
    <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="onLoad"
        :immediate-check="false"
        :offset="500"
      >
        <slot></slot>
      </van-list>
    </van-pull-refresh>
</template>

<script>
export default {
  data(){
    return {
      isLoading:false,
      loading:false,
      finished:false,  // 数据见底
    }
  },
  props:['refreshfunc','loaddata'],
  methods:{
    onLoad(){  // 加载更多数据
      // this.loading = true; // 正在加载中
      setTimeout(()=>{
          this.loaddata(()=>{
            this.loading = false;
            this.ShowToast('加载成功')

          },()=>{
            this.finished = true;
            this.ShowToast('数据见底了')
          })
        },1000)
    },
    onRefresh(){ // 刷新数据
        setTimeout(()=>{
          this.refreshfunc(()=>{
            this.isLoading = false;
            this.ShowToast('刷新成功')
          })
        },1000)
    }
  }
}
</script>
